﻿using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Configuration;
using ExtBusiness.User;
using ExtBusiness.CommonBusiness;
using ExtBusiness;
using ChBusiness.CommonBusiness;
using ChBusiness;

public partial class WebPubManager_UnitsEdit :PageBase
{
    private UserManager cUser = new UserManager();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindUnitsInfo();
        }
    }

    /// <summary>
    /// 绑定单位信息
    /// </summary>
    /// <!--addby zhongjian 20100412-->
    protected void BindUnitsInfo()
    {
        if (!string.IsNullOrEmpty(Request["id"]))
        {
            DataTable dt = cUser.GetUnits(Request["id"],"","","","");

            if (dt.Rows.Count > 0)
            {
                txtUnitsname.Text = BasicOperate.GetDataBaseString(dt.Rows[0]["unitsname"]);
                txtUnitsTel.Text = BasicOperate.GetDataBaseString(dt.Rows[0]["unitstel"]);
                txtUnitsaddress.Text = BasicOperate.GetDataBaseString(dt.Rows[0]["unitsaddress"]);
                txtPostcode.Text = BasicOperate.GetDataBaseString(dt.Rows[0]["postcode"]);
                txtFax.Text = BasicOperate.GetDataBaseString(dt.Rows[0]["fax"]);
                txtlegal.Text = BasicOperate.GetDataBaseString(dt.Rows[0]["legal"]);
                txtOrganization.Text = BasicOperate.GetDataBaseString(dt.Rows[0]["organization"]);
                txtNature.Text = BasicOperate.GetDataBaseString(dt.Rows[0]["nature"]);
            }
        }
    }

    protected void btnRefer_Click(object sender, EventArgs e)
    {
        //获取操作者ip地址
        string myIP = Common.IPOperation.GetIpAddress();

        string strId = Request["id"];
        if (string.IsNullOrEmpty(strId))
        {
            UserManager.AddUnitsInfo(txtUnitsname.Text, txtUnitsTel.Text, txtUnitsaddress.Text, txtFax.Text, txtPostcode.Text,
                txtlegal.Text, txtOrganization.Text, txtNature.Text);

            //添加操作日志 addby zhongjian 20100421
            string strRemark = "添加单位信息。用户ID: " + strId + ",单位名称:" + txtUnitsname.Text + "";
            SystemLogs.AddSystemLogs(Session["UserName"].ToString(), "add", strRemark, "",myIP);
        }
        else
        {
            UserManager.UpdateUnitsInfo(strId, txtUnitsname.Text, txtUnitsTel.Text, txtUnitsaddress.Text, txtFax.Text, txtPostcode.Text,
                txtlegal.Text, txtOrganization.Text, txtNature.Text);

            //添加操作日志 addby zhongjian 20100421
            string strRemark = "修改单位信息。用户ID: " + strId + ",单位名称:" + txtUnitsname.Text + "";
            SystemLogs.AddSystemLogs(Session["UserName"].ToString(), "update", strRemark, "",myIP);

            ////更新单位信息(地信接口)           
            //InterfaceOperation infaceOperation = new InterfaceOperation();
            //string strXml = infaceOperation.GetUnitsInfoXml(strId, "update");

            //if (!string.IsNullOrEmpty(strXml))
            //{
            //    try
            //    {
            //        DxInterface.IdsService idsTemp = new DxInterface.IdsService();

            //        string strCheckCode = Antu.Common.Encode.Md5(DateTime.Now.ToShortDateString());
            //        string strReturn = idsTemp.UserInfo(strXml, strCheckCode);

            //        if (!string.IsNullOrEmpty(strReturn))
            //        {
            //            if (!XmlHelper.HaveTargetString(strReturn, "UserInfoResponse", "true"))
            //            {
            //                infaceOperation.UpdateExceptionAndXml(strXml, "接口更新失败", 10);
            //            }
            //        }
            //        else
            //        {
            //            infaceOperation.UpdateExceptionAndXml(strXml, "接口返回值为空", 10);
            //        }
            //    }
            //    catch (Exception ex)
            //    {
            //        infaceOperation.UpdateExceptionAndXml(strXml, ex.Message, 10);
            //    }
            //}
        }
        Response.Redirect("UnitsList.aspx");
    }

    protected void btnReturn_Click(object sender, EventArgs e)
    {
        Response.Redirect("UnitsList.aspx");
    }
}
